package com.example.leetcode.tree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 给定一个二叉树的根节点 root ，返回 它的 中序 遍历 。
 *
 *
 * 思路：递归，左中右
 */
public class InorderTraversal {
    static List<Integer> result = new ArrayList<>();


    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);

        treeNode1.right = treeNode2;
        treeNode2.left = treeNode3;

        List<Integer> integers = inorderTraversal(treeNode1);
        System.out.println(integers);
    }

    public static List<Integer> inorderTraversal(TreeNode root) {
        if (root == null) {
            return Collections.emptyList();
        }

        inorderTraversal(root.left);
        result.add(root.val);
        inorderTraversal(root.right);


        return result;
    }
}
